﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>Door: Test/DoorTest/DoorTest.cs Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                C# examples using state machines generated by StateBuilderDotNet
            </h1>
            <h3>
                Door: Test/DoorTest/DoorTest.cs Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Test/DoorTest/DoorTest.cs</div>  </div>
</div>
<div class="contents">
<a href="_door_test_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿
<a name="l00002"></a><a class="code" href="namespace_state_forge_1_1_examples_1_1_door_1_1_test.html">00002</a> <span class="keyword">namespace </span>StateForge.Examples.<a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a>.Test
<a name="l00003"></a>00003 {
<a name="l00004"></a>00004     <span class="keyword">using</span> System;
<a name="l00005"></a>00005     <span class="keyword">using</span> System.Diagnostics;
<a name="l00006"></a>00006     <span class="keyword">using</span> System.Threading;
<a name="l00007"></a>00007     <span class="keyword">using</span> StateForge.StateMachine;
<a name="l00008"></a>00008     <span class="keyword">using</span> NUnit.Framework;
<a name="l00009"></a>00009     <span class="keyword">using</span> Rhino.Mocks;
<a name="l00010"></a>00010 
<a name="l00011"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html">00011</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html">EngineMock</a> : <a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">IEngine</a>
<a name="l00012"></a>00012     {
<a name="l00013"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html#afdef93f872f2aa56f619f668b628cda7">00013</a>         <span class="keyword">public</span> <a class="code" href="interface_state_forge_1_1_examples_1_1_door_1_1_i_engine.html">IEngine</a> Context { <span class="keyword">get</span>; <span class="keyword">set</span>; }
<a name="l00014"></a>00014 
<a name="l00015"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html#adc3049e79efe0d5a5a31f928bba4c43d">00015</a>         <span class="keyword">public</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html">EngineMock</a>()
<a name="l00016"></a>00016         {
<a name="l00017"></a>00017         }
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html#a2b8fe4ab93a476b4623d559d0e8565b0">00019</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> StartOpen()
<a name="l00020"></a>00020         {
<a name="l00021"></a>00021             this.Context.<a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html#a2b8fe4ab93a476b4623d559d0e8565b0">StartOpen</a>();
<a name="l00022"></a>00022         }
<a name="l00023"></a>00023 
<a name="l00024"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html#ade12ff306e97a3e16a479448ac06c430">00024</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> StartClose()
<a name="l00025"></a>00025         {
<a name="l00026"></a>00026             this.Context.StartClose();
<a name="l00027"></a>00027         }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html#a517d53e17f585aeed4a65bd5603b8171">00029</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Stop()
<a name="l00030"></a>00030         {
<a name="l00031"></a>00031             this.Context.Stop();
<a name="l00032"></a>00032         }
<a name="l00033"></a>00033     }
<a name="l00034"></a>00034 
<a name="l00038"></a>00038     [TestFixture]
<a name="l00039"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html">00039</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html" title="DoorTest tests the Door class.">DoorTest</a>
<a name="l00040"></a>00040     {
<a name="l00041"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#af1dcb1c7f46888b319b1dc4fcc84f3f8">00041</a>         <span class="keyword">public</span> <span class="keywordtype">int</span> DurationOpening { <span class="keyword">get</span>; <span class="keyword">set</span>; }
<a name="l00042"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a2b7cb6bf187e99d3b53540c61c2217b5">00042</a>         <span class="keyword">public</span> <span class="keywordtype">int</span> DurationOpenCosing { <span class="keyword">get</span>; <span class="keyword">set</span>; }
<a name="l00043"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ab2f2435fe47c4366ba154e02d6f4aa0c">00043</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ab2f2435fe47c4366ba154e02d6f4aa0c">door</a>;
<a name="l00044"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ade84c45ecedf410052045a1a8d05f5c9">00044</a>         <span class="keyword">private</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html">EngineMock</a> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ade84c45ecedf410052045a1a8d05f5c9">engineMock</a>;
<a name="l00045"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a2aacfec520fb0269244d6900139ab9be">00045</a>         <span class="keyword">private</span> <span class="keyword">static</span> readonly <span class="keywordtype">string</span> traceName = <span class="stringliteral">&quot;Test&quot;</span>;
<a name="l00046"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a6f37143e9c1ff674300f871df0a34437">00046</a>         <span class="keyword">private</span> <span class="keyword">static</span> TraceSource ts = <span class="keyword">new</span> TraceSource(traceName);
<a name="l00047"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a4aa528ffad852c6eb39671eb76f98fad">00047</a>         <span class="keyword">private</span> <span class="keyword">static</span> AutoResetEvent autoResetEvent = <span class="keyword">new</span> AutoResetEvent(<span class="keyword">false</span>);
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#aed67e7940f214982ad1c396e085cb444">00049</a>         <span class="keyword">public</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html" title="DoorTest tests the Door class.">DoorTest</a>()
<a name="l00050"></a>00050         {
<a name="l00051"></a>00051             Setup();
<a name="l00052"></a>00052         }
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a676f727b2675d9e717a3fc343b8b0de7">00054</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> StateMachineEnd(<span class="keywordtype">object</span> sender, EventArgs e)
<a name="l00055"></a>00055         {
<a name="l00056"></a>00056             ts.TraceInformation(<span class="stringliteral">&quot;Test State machine has ended&quot;</span>);
<a name="l00057"></a>00057             autoResetEvent.Set();
<a name="l00058"></a>00058         }
<a name="l00059"></a>00059 
<a name="l00060"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a3fe94e0c41a840e2a46469cd5cab9f6a">00060</a>         <span class="keyword">static</span> <span class="keywordtype">void</span> Main(<span class="keywordtype">string</span>[] args)
<a name="l00061"></a>00061         {
<a name="l00062"></a>00062             <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html" title="DoorTest tests the Door class.">DoorTest</a> doorTest = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html" title="DoorTest tests the Door class.">DoorTest</a>();
<a name="l00063"></a>00063             doorTest.<a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ac0379fee6701b4847b5c9169d40a027c">TestMethod01</a>();
<a name="l00064"></a>00064             ts.TraceInformation(<span class="stringliteral">&quot;Test has ended&quot;</span>);
<a name="l00065"></a>00065             Environment.Exit(0);
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067 
<a name="l00068"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#a4c2762f70cd419fedb34ca7368d1290f">00068</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> InitializeContext(ContextBase contextTest)
<a name="l00069"></a>00069         {
<a name="l00070"></a>00070             contextTest.Observer = ObserverTrace.Instance(traceName);
<a name="l00071"></a>00071             contextTest.RegisterEndHandler(<span class="keyword">new</span> EventHandler&lt;EventArgs&gt;(StateMachineEnd));
<a name="l00072"></a>00072             contextTest.EnterInitialState(); 
<a name="l00073"></a>00073         }
<a name="l00074"></a>00074 
<a name="l00075"></a>00075         [SetUp]
<a name="l00076"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#af8dd0f90463c442774df3aa770e80a80">00076</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> Setup()
<a name="l00077"></a>00077         {
<a name="l00078"></a>00078             DurationOpening = 2000;
<a name="l00079"></a>00079             DurationOpenCosing = 2000;
<a name="l00080"></a>00080             this.engineMock = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_engine_mock.html">EngineMock</a>();
<a name="l00081"></a>00081             this.door = <span class="keyword">new</span> <a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_door.html">Door</a>(engineMock);
<a name="l00082"></a>00082         }
<a name="l00083"></a>00083 
<a name="l00084"></a>00084         [Test]
<a name="l00085"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ac0379fee6701b4847b5c9169d40a027c">00085</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> TestMethod01()
<a name="l00086"></a>00086         {
<a name="l00087"></a>00087             var contextTest = <span class="keyword">new</span> DoorTest01Context(<span class="keyword">this</span>, door);
<a name="l00088"></a>00088             this.engineMock.Context = contextTest;
<a name="l00089"></a>00089             InitializeContext(contextTest);
<a name="l00090"></a>00090             autoResetEvent.WaitOne();
<a name="l00091"></a>00091         }
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         [Test]
<a name="l00094"></a><a class="code" href="class_state_forge_1_1_examples_1_1_door_1_1_test_1_1_door_test.html#ac5d4146195c93a16f1499036064dbba6">00094</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> TestMethod02()
<a name="l00095"></a>00095         {
<a name="l00096"></a>00096             var contextTest = <span class="keyword">new</span> DoorTest02Context(<span class="keyword">this</span>, door);
<a name="l00097"></a>00097             this.engineMock.Context = contextTest;
<a name="l00098"></a>00098             InitializeContext(contextTest);
<a name="l00099"></a>00099             autoResetEvent.WaitOne();
<a name="l00100"></a>00100         }
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
